import ajax from '@/utils/ajax'

export function modifyPwd(oldPwd, newPwd) {
    return ajax.post('/sys/user/modifyPwd', {
        oldPwd: oldPwd,
        newPwd: newPwd
    }, true)
}

export function login(params) {
    return ajax.post(
        '/sys/user/login', params,
    )

}

export function getRouters() {
    return ajax.post(
        '/sys/user/getMenuData'
    )
}

export function logout() {
    return ajax.post('/sys/user/logout')
}

export function getUserSelectData() {
    return ajax.post('/sys/user/getUserSelectData')
}


export function getStoreSelectData() {
    return ajax.post('/sys/user/getStoreSelectData')
}

export const list = function (accountId, userType) {
    return ajax.post('/sys/user/list', {
        accountId: accountId,
        userType: userType
    })
}
export const load = function (id) {
    return ajax.post('/sys/user/loadMore', {
        id: id
    }, true)
}

export const save = function (form) {
    return ajax.post('/sys/user/save', form)
}

export const active = function (id) {
    return ajax.post('/sys/user/active', {
        id: id
    }, true)
}
export const freeze = function (id) {
    return ajax.post('/sys/user/freeze', {
        id: id
    }, true)
}
export const resetPwd = function (id) {
    return ajax.post('/sys/user/resetPwd', {
        id: id
    }, true)
}
export const del = function (id) {
    return ajax.post('/sys/user/del', {
        id: id
    }, true)
}

export const getRoleSelectData = function () {
    return ajax.post('/sys/user/getRoleSelectData')
}

export const pagination = function (tblOpts, conditions) {
    let params = {
        pageNo: tblOpts.pageNo || 1,
        pageSize: tblOpts.pageSize || 50,
        conditions: conditions || []
    }
    if (tblOpts.prop) {
        Object.assign(params, {
            sort: tblOpts.prop,
            order: tblOpts.order === 'descending' ? 'desc' : 'asc'
        })
    }
    return ajax.post('/sys/user/pagination', params, false)
}
